import * as projectApi from '@/utils/project-api';
import type { ProjectInfo } from '@/types/ProjectInfo';

export class Project {
  constructor() {}

  public async getAsync(startIndex: number, length: number) {
    const result = await projectApi.getProjectsAsync(startIndex, length);
    if (result.isSuccess) {
      return result.result!;
    } else {
      throw result.message;
    }
  }

  public async insertAsync(newProject: ProjectInfo) {
    const result = await projectApi.insertProjectAsync(newProject);
    if (!result.isSuccess) {
      throw result.message;
    }
  }

  public async deleteAsync(id: string) {
    const result = await projectApi.deleteProjectAsync(id);
    if (!result.isSuccess) {
      throw result.message;
    }
  }
}
